<template>
	<view class="content" >
		<view class="tabs">
			<view class="tabItem" @click="btnChangeClick(0)">
				<image src="../../static/msg_logistics_icon.png" mode=""></image>
				<view class="lab3" :class="current == 0 ? 'activeItem':''">{{msgDict.lab1}}</view>
				<view class="line" v-if="current == 0"></view>
				<view class="LNum" v-if="lab0Num>0">{{lab0Num}}</view>
			</view>
			<view class="tabItem" @click="btnChangeClick(1)">
				<image src="../../static/msg_system_icon.png" mode=""></image>
				<view class="lab3" :class="current == 1 ? 'activeItem':''">{{msgDict.lab1Title}}</view>
				<view class="line" v-if="current == 1"></view>
				<view class="LNum" v-if="lab1Num >0">{{lab1Num}}</view>
			</view>
		</view>
		<view class="items" v-if="current == 0" v-for="(item,index) in wuliuList" :key='index'>
			<view class="labTopName">
				<view class="viewName">
					<view class="ball" v-if="item.readFlag == 0"></view>
					<view class="labType labTypeActive">交易</view>
					<view class="labTitle">{{item.titile}}</view>
				</view>
				<view class="itemTime">{{item.sendTime}}</view>
			</view>
			<view class="labContent ellipsis--2" >{{item.msgAbstract}}</view>
			<view class="contentGroud" @click="gotoShopping(item.id,index)">
				<view class="labDetail">查看详情</view>
			    <uni-icons type="arrowright" size="15" color="#999"></uni-icons>
			</view>
		   
		</view>
		<view class="items" v-if="current == 1"  v-for="(item,index) in sysList" :key='index'>
			<view class="labTopName">
				<view class="viewName">
					<view class="ball" v-if="item.readFlag == 0"></view>
					<view class="labType">公告</view>
					<view class="labTitle">{{item.titile}}</view>
				</view>
				<view class="itemTime">{{item.sendTime}}</view>
			</view>
			<view class="labContent ellipsis--2" >{{item.msgAbstract}}</view>
			<view class="contentGroud" @click="gotoShopping(item.id,index)">
				<view class="labDetail">查看详情</view>
			    <uni-icons type="arrowright" size="15" color="#999"></uni-icons>
			</view>
		   
		</view>

	</view>
</template>

<script>
	import {viewSysMsg} from '../../api/index.js'
	export default {
		data() {
			return {
				userId:undefined,
				
				sysList:[],
				wuliuList:[],
				lab1Num:0,
				lab0Num:0,
				listIndex0:1,
				listIndex1:1,
				listTotal0: 0,
				listTotal1:0,
				current: 0,//顶部标签 0 物流  1 系统
				
				
				lab2Title:'',
				lab1Title:'',
				msgDict:{},
				showNeedListBool:false
				
			}
		},
		
		onLoad() {
			
			this.userId = getApp().globalData.userId
			this.msgDict = getApp().globalData.$t('infoCenter');
			this.getWuliuCouponList()
			//交易物流
			this.getSysCouponList();
			//系统消息
	
		},
		onPullDownRefresh() {
			if (this.current == 0) {
				this.getWuliuCouponList()
				//交易物流
			} else{
				this.getSysCouponList();
				//系统消息
			}
			
			
		},
		//上拉加载
		onReachBottom() {
			if (this.current == 0) {
				if (this.listTotal0 > this.listIndex0 * 10) {
					
					this.listIndex0++;
					this.getWuliuCouponList();
				}
			} else{
				if (this.listTotal1 > this.listIndex1 * 10) {
					
					this.listIndex1++;
					this.getSysCouponList();
				}
			}
			
		},
		onShow(){
			
			if (this.showNeedListBool) {
				
				this.showNeedListBool = false
				
				if (this.current == 0) {
		       this.getWuliuCouponList()
				} else{
			  this.getSysCouponList();
				}
				
			
				
			}
			
		},
		
		methods: {
			gotoShopping(myId,index){
				if (this.current == 0) {
					let item = this.wuliuList[index];
					// console.log('34',item,index)
					// debugger
					if (item.readFlag == 0) {
					item.readFlag = 1;
					
					this.wuliuList.splice(index,1,item);
					this.lab0Num --;
						
					}
					
					uni.navigateTo({
						url:'../infoDeatil/infoDeatil?id='+myId
					})
				} else{
					let item = this.sysList[index];
					if (item.readFlag == 0) {
					item.readFlag = 1;
					
					this.sysList.splice(index,1,item);
					this.lab1Num --;
					}
					
					uni.navigateTo({
						url:'../infoDeatil/infoDeatil?id='+myId
					})
				}
				
			},
			gotoSys(){
				uni.navigateTo({
					url:'../sysInfolist/sysInfolist'
				})
			},
			btnChangeClick(key){
				this.current = key;
				// if (key == 0) {
				// 	this.getWuliuCouponList()
				// } else{
				// 	this.getSysCouponList();
				// }
			
			},
			async getSysCouponList(key) {
			
					let {result} = await viewSysMsg({
						pageNo:this.listIndex1,
						pageSize: 10,
						smgType:'1',
						userId:this.userId,
					});
					
					if (this.listIndex1 > 1) {
						this.sysList =this.sysList.concat(result.sysMsgList)
					} else {
						this.sysList = result.sysMsgList;
					}
					
					this.listTotal1 = result.noReadSysMsgTotal;
					this.lab1Num=result.sysMsgTotal
					
					uni.stopPullDownRefresh();
			},
			async getWuliuCouponList() {
			
					let {result} = await viewSysMsg({
						pageNo:this.listIndex0,
						pageSize: 10,
						smgType:'2',
						userId:this.userId,
					});
					
					if (this.listIndex0 > 1) {
						this.wuliuList =this.wuliuList.concat(result.sysMsgList)
					} else {
						this.wuliuList = result.sysMsgList;
					}
				    this.lab0Num=result.noReadSysMsgTotal
				    this.listTotal0 = result.sysMsgTotal;
					uni.stopPullDownRefresh();
			},
		
		}
	}
</script>

<style lang="less">
	page{
		background-color: #F8F9FD;
		height: 100%;
	}
	.tabs{
		background-color: #fff;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 5;
		width: 750rpx;
		height: 100rpx;
		display: flex;
		.tabItem:last-child{
			border-left: thin solid #f2f2f2;
		}
		.tabItem{
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			.lab3{
				color: #333333;
				font-size: 32rpx;
				font-weight: 400;
				
			}
			.activeItem{
				color: #0005C9;
			}
			image{
				width: 60rpx;
				height: 60rpx;
				margin-top: 6rpx;
			}
			.line{
				position: absolute;
				bottom: 10rpx;
				right: 90rpx;
				height: 4rpx;
				width: 180rpx;
				background-color: #2D63F9;
			}
			.LNum{
				position: absolute;
				right: 70rpx;
				bottom: 60rpx;
				color: #fff;
				font-size: 24rpx;
				font-weight: 200;
				background-color: #F54353;
				height: 36rpx;
				text-align: center;
				padding: 0 12rpx;
				border-radius: 18rpx;
			}
		}
		
	}
    
	.content{
		padding:100rpx 20rpx 0;
		
	}
	.items{
		padding:0 20rpx;
		border-radius: 6rpx;
		background-color: #fff;
		position: relative;
		margin-bottom: 20rpx;
		
		.labTopName{
			
			margin-top: 20rpx;
			padding: 20rpx 0;
			border-bottom: thin solid #F4F4F4;
			
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-weight: 400;
			
			.viewName{
				display: flex;
				align-items: center;
				.labType{
					height: 30rpx;
					padding: 0rpx 6rpx;
					background: #FAAC33;
					border-radius: 3rpx;
					
					color: #FFF;
					font-size: 22rpx;
					margin-right: 10rpx;
				}
				.labTypeActive{
					background: #FC6B88;
				}
				.labTitle{
					color: #333;
					font-size: 30rpx;
				}
				.ball{
					width: 10rpx;
					height:10rpx;
					border-radius: 50%;
					background-color: #F54353;
					margin-right: 10rpx;
					/* position: absolute;
					top: 20rpx;
					left: 20rpx; */
					
				}
				
			}
			.itemTime{
				
				font-size: 24rpx;
				color: #999999;
			}
			
		}
		.labContent{
			color: #666;
			font-size: 26rpx;
			padding: 40rpx 10rpx;
			
		}
		.contentGroud{
			
			border-top: thin solid #F4F4F4;
			
			padding: 20rpx 0;
			display: flex;
			justify-content:space-between;
			align-items: center;
			color: #333;
			font-size: 24rpx;
		}
		
		
	}


</style>
